<?php
/**
 * Created by PhpStorm.
 * Date: 2018/9/13
 * Time: 下午6:38
 */
class m_bacteria extends CI_Model{

    function __construct (){
        parent::__construct();
        $this->load->database();
    }
    function getdata(){
        $query=$this->db->get('image');
        return $query->result();
    }
    function idmax(){
        $sql="select image_id from image";
        $query = $this->db->query($sql);
        $temp = $query->result_array();
        $max=0;
        foreach($temp as $value){
            if($max==0||$max<$value['image_id'])
            {
                $max=$value['image_id'];
            }
        }
//            $imagemax=$value['image_id'];
        return $max;
//        echo $temp[0];

    }

    function insert($arr){

        $this->db->insert('spectrum_data',$arr);
//        $this->db->insert('bacteria_update',$arr);
        return true;
    }
    function addspec($arr){

        $this->db->insert('specimen',$arr);
        return true;
    }
    function insertImage($arr){

        $this->db->insert('image',$arr);
//        $this->db->insert('bacteria_update',$arr);
        return true;
    }
    function deleteById($data_id){

        $this->db->delete('spectrum_data',array('data_id'=>$data_id));
        return true;
    }
    function deleteImageById($image_id){

        $this->db->delete('image',array('image_id'=>$image_id));
        $this->db->delete('spectrum_data',array('image_id'=>$image_id));
        return true;
    }
    function deleteImageByIdspec($specimen_id){

        
        $this->db->delete('specimen',array('specimen_id'=>$specimen_id));
        return true;
    }

    function update($image_id,$arr){
        $this->db->where('image_id',$image_id);
        $this->db->update('image',$arr);
        return true;
    }
    function updatespec($specimen_id,$arr){
        $this->db->where('specimen_id',$specimen_id);
        $this->db->update('specimen',$arr);
        return true;
    }
    function dataupdate($data_id,$arr){
        $this->db->where('data_id',$data_id);
        $this->db->update('spectrum_data',$arr);
        return true;
    }
    function download($image_id){
        if(!$image_id)
        {
            return array();
        }
        //的到书籍信息
        $sql="select * from spectrum_data where image_id='$image_id'";
        //$query = $this->db->get_where('bacteria',array('bac_id'=>$bac_id));
        //$row = $query->result_array();
        $query = $this->db->query($sql);
        $temp = $query->result_array();
        //print_r($temp);
        //echo $bac_id;
        return $temp;
    }
    function downloadq($image_id){
        if(!$image_id)
        {
            return array();
        }
        //的到书籍信息
        $sql="select * from image where image_id='$image_id'";
        //$query = $this->db->get_where('bacteria',array('bac_id'=>$bac_id));
        //$row = $query->result_array();
        $query = $this->db->query($sql);
        $temp = $query->result_array();
//        echo $temp[0];
        //print_r($temp);
        return $temp;
    }
    function queryById($image_id){
        if(!$image_id)
        {
            return array();
        }
        //的到书籍信息
        $sql="select * from image where image_id='$image_id'";
        //$query = $this->db->get_where('bacteria',array('bac_id'=>$bac_id));
        //$row = $query->result_array();
        $query = $this->db->query($sql);
        $temp = $query->result_array();
        //print_r($temp);
        //echo $bac_id;
        return $temp;
    }
    function queryByPage(){
        $query=$this->db->get('image');
        return $query->result();
    }

    function getDataCount($options = array()){
        $query = $this->find_bacteria_count($options);
        $total = $query->num_rows();
        return $total;
    }
    function find_bacteria_front($options = array(),$count=20, $offset)
    {
        if(!is_array($options))
        {
            //echo '没有设置查询规则books_model line 229';
            return array();
        }
        if ($count)
        {
            //$this->db->limit((int)$count, (int)$offset);
            $limit = " limit $offset,$count";
        }
        //没有图书类型，只有查询方式和相应关键字

        //查询方式不为空且关键字不为空
        if($options['keywords'] != '')
        {
            //echo '221';
            $keywords = $options['keywords'];
            $sql = "select * from image where ((image_id LIKE '%$keywords%') or (image_name LIKE '%$keywords%') or (image_Latin_name LIKE '%$keywords%') or (image_data LIKE '%$keywords%'))".$limit;
        }
        else if($options['keywords'] == '')
        {
            //////echo '237';
            $sql = "select * from image". $limit;
        }
        //echo $sql;
        $query = $this->db->query($sql);
//        $rows = $query->row_array();
//         print_r($rows);
        $temp = $query->result_array();
        //print_r($temp);
        return $temp;
    }
    function find_bacteria_frontspec($options = array(),$count=20, $offset)
    {
        if(!is_array($options))
        {
            //echo '没有设置查询规则books_model line 229';
            return array();
        }
        if ($count)
        {
            //$this->db->limit((int)$count, (int)$offset);
            $limit = " limit $offset,$count";
        }
        //没有图书类型，只有查询方式和相应关键字

        //查询方式不为空且关键字不为空
        if($options['keywords'] != '')
        {
            //echo '221';
            $keywords = $options['keywords'];
            $sql = "select * from specimen where ((specimen_id LIKE '%$keywords%') or (specimen_name LIKE '%$keywords%') or (specimen_source LIKE '%$keywords%') or(specimen_latin LIKE '%$keywords%') or (specimen_no LIKE '%$keywords%'))".$limit;
        }
        else if($options['keywords'] == '')
        {
            //////echo '237';
            $sql = "select * from specimen". $limit;
        }
        //echo $sql;
        $query = $this->db->query($sql);
//        $rows = $query->row_array();
//         print_r($rows);
        $temp = $query->result_array();
        //print_r($temp);
        return $temp;
    }

    function find_bacteria_count_front($options = array())
    {
        if(!is_array($options))
        {
            //echo '没有设置查询规则books_model line 229';
            return array();
        }

        //没有图书类型，只有查询方式和相应关键字

        //查询方式不为空且关键字不为空
        if($options['keywords'] != '')
        {
            //echo '369';
            $keywords = $options['keywords'];
            $sql = "select * from image where ((image_id LIKE '%$keywords%') or (image_name LIKE '%$keywords%') or (image_Latin_name LIKE '%$keywords%') or (image_name LIKE '%$keywords%') )";
        }
        else if($options['keywords'] == '')
        {
            //echo '385';
            $sql = "select * from image";
        }
        else
        {
            echo '查询条件错误';
        }


        $query = $this->db->query($sql);
        return $query;
    }
    function find_bacteria_count_frontspec($options = array())
    {
        if(!is_array($options))
        {
            //echo '没有设置查询规则books_model line 229';
            return array();
        }

        //没有图书类型，只有查询方式和相应关键字

        //查询方式不为空且关键字不为空
        if($options['keywords'] != '')
        {
            //echo '369';
            $keywords = $options['keywords'];
            $sql = "select * from specimen where ((specimen_id LIKE '%$keywords%') or(specimen_latin LIKE '%$keywords%') or (specimen_name LIKE '%$keywords%') or (specimen_no LIKE '%$keywords%') or (specimen_source LIKE '%$keywords%') )";
        }
        else if($options['keywords'] == '')
        {
            //echo '385';
            $sql = "select * from specimen";
        }
        else
        {
            echo '查询条件错误';
        }


        $query = $this->db->query($sql);
        return $query;
    }

    function getDataCount_front($options = array()){
        $query = $this->find_bacteria_count_front($options);
        $total = $query->num_rows();
        return $total;
    }
    function getDataCount_frontspec($options = array()){
        $query = $this->find_bacteria_count_frontspec($options);
        $total = $query->num_rows();
        return $total;
    }
    function getDataCount_i($options = array()){
        $query = $this->find_bacteria_count_front($options);
        $total = $query->num_rows();
        return $total;
    }
    function getDataCount_ispec($options = array()){
        $query = $this->find_bacteria_count_frontspec($options);
        $total = $query->num_rows();
        return $total;
    }
    function queryById_front($image_id){
        if(!$image_id)
        {
            return array();
        }
        //信息
        $sql="select * from spectrum_data where image_id='$image_id'";
        $query = $this->db->query($sql);
        $temp = $query->result_array();
        //print_r($temp);
        //echo $bac_id;
        return $temp;
    }
    function queryById_frontspec($specimen_id){
        if(!$specimen_id)
        {
            return array();
        }
        //信息
        $sql="select * from specimen where specimen_id='$specimen_id'";
        $query = $this->db->query($sql);
        $temp = $query->result_array();
        //print_r($temp);
        return $temp[0];
    }

    function querydataById_front($data_id){
        if(!$data_id)
        {
            return array();
        }
        //的到书籍信息
        $sql="select * from spectrum_data where data_id='$data_id'";
        //$query = $this->db->get_where('bacteria',array('bac_id'=>$bac_id));
        //$row = $query->result_array();
        $query = $this->db->query($sql);
        $temp = $query->result_array();
        //print_r($temp);
//        echo $data_id;
        return $temp[0];
    }
    function queryImageById_front($image_id){
        if(!$image_id)
        {
            return array();
        }
        //的到书籍信息
        $sql="select * from image where image_id='$image_id'";
        //$query = $this->db->get_where('bacteria',array('bac_id'=>$bac_id));
        //$row = $query->result_array();
        $query = $this->db->query($sql);
        $temp = $query->result_array();

        //echo $bac_id;
        return $temp[0];
    }
    function queryspecById_front($specimen_id){
        if(!$specimen_id)
        {
            return array();
        }
        //的到书籍信息
        $sql="select * from specimen where specimen_id='$specimen_id'";
        $query = $this->db->query($sql);
        $temp = $query->result_array();

        //echo $bac_id;
        return $temp[0];
    }

}
?>